import request from '@/common/request/request.js'
import {
	stringFormat
} from '../utils/util.js' //组件用正则 过滤传递的参数

const GET = 'GET'
const POST = 'POST'
const PUT = 'PUT'
const DELETE = 'DELETE'

import {
	PMCP_URL
} from '@/common/utils/config.js'

export function isPaychakraScl(data) {
	return request(data, "/merchandise/isPayChakraScl", GET).then(res => res)
}
export function getMerchandiseReportId(data) {
	return request(data, "/merchandise/report/getMerchandiseReportId", GET).then(res => res)
}
export function getMerchandiseReportPage(data) {
	return request(data, "/merchandise/report/getMerchandiseReportPage", GET).then(res => res)
}
export function editMerchandiseReport(data) {
	return request(data, "/merchandise/report/editMerchandiseReport", POST).then(res => res)
}

export function defaultShippingAddress(data) {
	return request(data, "/shipping/address/defaultShippingAddress", GET).then(res => res)
}

export function address_add(data) {
	return request(data, "/shipping/address/add", POST).then(res => res)
}
export function get_site_list(data) {
	return request(data, "/api_site/get_site_list", GET).then(res => res)
}

// 判断首页第一个图是否展示
export function hasRemoteConsult() {
	return request(null, "/order/hasRemoteConsult", POST).then(res => res)
}
// 判断是否首单
export function getOrderExtFirstOrder() {
	return request(null, "/storeUserMiniAppOrder/extFirstOrder", POST).then(res => res)
}

// 小程序授权
export function userLogin(data) {
	return request(data, "/login", POST).then(res => res)
}

//获取banner
export function banner(data) {
	return request(data, "/homePage/banner", GET).then(res => res)
}

//获取分类 - 旧版
export function categories(data) {
	return request(data, "/consultant/categories", GET).then(res => res)
}

//获取咨询师擅长领域-筛选选项
export function getConsultantLabelOpts(data) {
	return request(data, "/label/getLabelParent", GET).then(res => res)
}



//首页推荐咨询师
export function consultants(data) {
	return request(data, "/consultant/recommend", GET).then(res => res)
}

//根据分类获取咨询师/consultant/{categoryId}/{sort}
export function getConsultingListByCategoryId(data, params) {
	// return request(data, stringFormat("/consultant/{0}/{1}", params), GET).then(res => res)
	return request(data, "/consultant/recommend", GET).then(res => res)
}


//根据咨询师id查询咨询师详情/consultant/detail/{consultantId}
export function getConsultantDetailByConsultantId(data, params) {
	// return request(data, stringFormat("/consultant/detail/{0}", params), GET).then(res => res)
	return request(data, "/consultant/getConsultantDetails", GET).then(res => res)
}


//咨询师咨询排班/schedule/scheduleDetail/{cosultantId}/{dateTime}
export function getScheduleDetailByCosultantId(data, params) {
	return request(data, stringFormat("/consultant/cosultantSchedul/{0}/{1}", params), GET).then(res => res)
}

export function getDayTwoWeek(data) {
	return request(data, "/consultant/getDayTwoWeek", GET).then(res => res)
}
// /consultant/getTimeToday/{dayEng}/{time}
export function getTimeToday(data, params) {
	return request(data, stringFormat("/consultant/getTimeToday/{0}/{1}/{2}", params), GET).then(res => res)
}

export function consultantListOrderDate(data, params) {
	return request(data, stringFormat("/consultant/consultantList/{0}/{1}/{2}", params), GET).then(res => res)
}


//rest请求封装  params：['13132','sdfjsdkj','fsdfsd']
export function get_pay_wx_info(data, params) {
	return request(data, stringFormat("/order/{0}/{1}/{2}", params), POST).then(res => res)
}

// 门诊排班
export function utpatientScheduling(data, params) {
	return request(data, stringFormat("/consultant/outpatientSchedul/{0}", params), GET).then(res => res)
}

export function getUtpatientScheduling(data) {
	return request(data, "/consultant/outpatientSchedul", GET).then(res => res)
}


// 订单确认
export function acknowledgementOrder(data) {
	return request(data, "/order/orderConfirm", POST).then(res => res)
}
export function wxPayCallback(data) {
	return request(data, "/storeUserMiniAppOrder/wxPayCallback", POST).then(res => res)
}
// 订单支付 订单创建
export function orderPayment(data) {
	data['orderScore'] = uni.getSystemInfoSync().uniPlatform == 'mp-toutiao' ? 'dy' : 'wx';
	return request(data, "/order/orderPay", POST).then(res => res)
}

export function submitBookingOfflineConsult(data) {
	return request(data, "/storeUserMiniAppOrder/submitBookingOfflineConsult", POST).then(res => res)
}


// 我的订单 tabTypa
export function orderList(data, params) {
	return request(data, stringFormat("/clientUser/orderList/{0}", params), GET).then(res => res)
}


// // 我的订单 tabTypa
// export function orderList(data,params) {
// 	return request(data,`/clientUser/orderList/${params}`,GET).then(res => res)
// }


// 我的订单 orderId
export function orderDetail(data, params) {
	return request(data, stringFormat("/clientUser/orderDetail/{0}", params), GET).then(res => res)
}

// 我的订单 /clientUser/list
export function getClientUserInfo(data) {
	return request(data, "/getLoginUser?apifoxResponseId=189587532", GET).then(res => res)
}

// order/orderPhone/{orderId}/{phone}
export function orderPhone(data, params) {
	return request(data, stringFormat("/order/orderPhone/{0}/{1}", params), PUT).then(res => res)
}

// 获取手机号/clientUser/getPhone/{signature}/{rawData}/{encryptedData}/{iv}
export function getPhone(data) {
	return request(data, "/clientUser/getPhone", POST).then(res => res)
}

// 门诊下单/order/outpatientAddorder
export function outpatientAddorder(data) {
	data['orderScore'] = uni.getSystemInfoSync().uniPlatform == 'mp-toutiao' ? 'dy' : 'wx';
	return request(data, "/order/outpatientAddorder", POST).then(res => res)
}

// 门诊详情/outpatientOrder/outpatientInfo/{outpatientId}
export function outpatientInfo(data, params) {
	return request(data, stringFormat("/outpatientOrder/outpatientInfo/{0}", params), PUT).then(res => res)
}
// 远程咨询下单
export function rematoAddorder(data) {
	// return request(data, "/order/longConsult", POST).then(res => res)
	return request(data, "/storeUserMiniAppOrder/submitBookingOnlineConsult", POST).then(res => res)
}
// 权益优惠券表_列表
export function getCouponList(data) {
	return request(data, "/equityCoupon/coupon_list").then(res => res)
}
// 添加用户权益
export function saveEquity(data) {
	return request(data, "/equity/save_equity", POST).then(res => res)
}

//获取用户余额体验券及是否有权限生成
export function getUserInfoEquity(data) {
	return request(data, "/equityLog/balance_and_coupon").then(res => res)
}
//获取权益余额列表
export function getBalanceList(data) {
	return request(data, "/equityLog/balance_by_type", POST).then(res => res)
}
//获取优惠券列表
export function getEquityList(data) {
	return request(data, "/equityLog/coupon_by_type", POST).then(res => res)
}

// 我的页面》去充值》充值确认  
// 参数：  {amount："金额"}
export function payBalance(data) {
	data['orderScore'] = uni.getSystemInfoSync().uniPlatform == 'mp-toutiao' ? 'dy' : 'wx';
	return request(data, "/order/personal_recharge_order", POST).then(res => res)
}

//订单页内的余额支付
export function balanceOrderPay(data) {
	return request(data, "/order/balance_order_pay", POST).then(res => res)
}


// 获取小程序码
export function getQrcodeUrl(data) {
	return request(data, "/clientTask/getQrCodeUrl", GET).then(res => res)
}


export function exchangeGoods(data) {
	return request(data, "/conversion/conversionRights", POST).then(res => res)
}


export function addLog(data) {
	return request(data, "/scl/log/add", POST).then(res => res)
}


export function getAppDictConfig(data) {
	return request(data, "/dictData/appCloseConfig", GET).then(res => res)
}


// sclIntroduce/sclIntroduce



/**
 * 获取权益列表
 * 2023-05-11
 * @param {Object} data 
 */
// export function getBalanceList(data) {
//   return request(data, "/equityLog/balance_by_type", POST).then(res => res)
// }


//从服务端获取oss上传临时token
export function initOssSTS(data) {
	return new Promise((resolve, reject) => {
		uni.showLoading()
		uni.request({
			url: PMCP_URL + '/foreign/oss/sts/getStsTokenInfo',
			method: 'post',
			dataType: 'json',
			data: data,
			header: {
				'content-type': "application/x-www-form-urlencoded"
			},
			success: res => {
				uni.hideLoading()
				console.log(res);
				resolve(res);
			},
			fail: err => {
				uni.hideLoading()
				reject(err)
			}
		})
	}).catch(err => console.log(err))
}